package com.search.web;

import com.hmall.common.clients.FeginClient;
import com.hmall.common.dto.PageDTO;
import com.search.pojo.ItemDoc;
import com.search.pojo.RequestParams;
import com.search.sevice.ISearchService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author zx
 * @date 2021/11/8 8:51
 */
@Slf4j
@RestController
@RequestMapping("/search")
public class SearchController {

    @Autowired
    ISearchService searchService;

    @Autowired
    FeginClient feginClient;

    /**
     * 搜索框自动补全
     * @param key
     * @return
     */
    @GetMapping("/suggestion")
    List<String> listAll(@RequestParam(name = "key") String key){
        List<String> list=searchService.finadAll(key);
//        searchService.list();
        return list;
    }

    /**
     * 过滤
     * @param param
     * @return
     */
    @PostMapping("/filters")
    public Map<String, List<String>> filters(@RequestBody RequestParams param) {
        Map<String, List<String>> filter = searchService.filter(param);
        return filter;
    }

    /**
     * 搜索
     * @param param
     * @return
     */
    @PostMapping("/list")
    public PageDTO<ItemDoc> Search(@RequestBody RequestParams param) {
        PageDTO<ItemDoc> search = searchService.search(param);
        return search;
    }
}
